package com.ruoyi.report.controller.report;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.report.domain.HanZaiCuStsTate;
import com.ruoyi.report.domain.HanZaiCustomerInfo;
import com.ruoyi.report.domain.HanZaiProjectInfo;
import com.ruoyi.report.service.HanZaiProjectInfoService;
import com.ruoyi.report.service.HanZaiCuStsTateService;
import com.ruoyi.report.service.HanZaiCustomerInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Created by IntelliJ IDEA.
 * User: 憨憨爱崽崽
 * Name: HanZaiCustomerInfoController 客户端通讯录报表
 * Date: 2022/3/28
 * Time: 11:17
 **/
@RestController
@RequestMapping("/house_sale")
public class HanZaiCustomerInfoController extends BaseController {
    @Autowired
    private HanZaiCustomerInfoService customerInfoService;
    @Autowired
    private HanZaiProjectInfoService projectInfoService;

    @Autowired
    private HanZaiCuStsTateService cuStsTateService;
    @PreAuthorize("@ss.hasPermi('house_sale:CustomerInfo:list')")
    @GetMapping("/CustomerInfo/list")
    public TableDataInfo list(HanZaiCustomerInfo customerInfo) {
        startPage();
        List<HanZaiCustomerInfo> list = customerInfoService.selectCustomerInfoList(customerInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('house_sale:projectName:list')")
    @GetMapping("/projectName/list")
    public TableDataInfo projectNameOptions() {
        List<HanZaiProjectInfo> list = projectInfoService.selectProjectInfoList(new HanZaiProjectInfo());
        List<HanZaiProjectInfo> result = new ArrayList();
        for (HanZaiProjectInfo projectInfo : list){
            HanZaiProjectInfo info = new HanZaiProjectInfo();
            info.setProjectid(projectInfo.getProjectid());
            info.setProjectname(projectInfo.getProjectname());
            result.add(info);
        }
        return getDataTable(result);
    }

    @PreAuthorize("@ss.hasPermi('house_sale:custtype:list')")
    @GetMapping("/custtype/list")
    public TableDataInfo custtypeOptions() {
        startPage();
        List<HanZaiProjectInfo> list = projectInfoService.selectProjectInfoList(new HanZaiProjectInfo());
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('house_sale:custstate:list')")
    @GetMapping("/custstate/list")
    public TableDataInfo custstateOptions() {
        List<HanZaiCuStsTate> list = cuStsTateService.selectCuStsTateList();
        return getDataTable(list);
    }


    /**
     * 导出客户资料列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:export')")
    @Log(title = "客户资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HanZaiCustomerInfo customerInfo) {
        List<HanZaiCustomerInfo> list = customerInfoService.selectCustomerInfoList(customerInfo);
        ExcelUtil<HanZaiCustomerInfo> util = new ExcelUtil<HanZaiCustomerInfo>(HanZaiCustomerInfo.class);
        util.exportExcel(response, list, "客户资料数据");
    }

}
